package com.ganbo.ms.nio;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.charset.StandardCharsets;

/**
 * @author ganbo
 * @date 2022/11/26 17:44
 */
public class Channel1 {

    public static void main(String[] args) throws IOException {

        String str = "hello 尚硅谷";

        FileOutputStream fileInputStream = new FileOutputStream("c:/hello111.txt");
        FileChannel channel = fileInputStream.getChannel();

        ByteBuffer buffer = ByteBuffer.allocate(1024);
        buffer.put(str.getBytes(StandardCharsets.UTF_8));

        buffer.flip();

        channel.write(buffer);

        channel.close();


    }
}
